class Utils {
	zeroPadding (str) {
		if (str.length < 2) {
			str = '0' + str;
		}
		return str;
	}
	//判断字符是否为空
	isEmpty (obj) {
		return (typeof obj === 'undefined' || obj === null || obj === "");
	}
	//数字转字符串
	numberToString (value) {
		if (value === "" || value == null || typeof value === 'undefined') {
			return '';
		} else if (!isNaN(value)) {
			return value + '';
		} else if (typeof (value) == 'string') {
			return value;
		}
		return '';
	}
	//是否字符串
	isString (val) {
		return Object.prototype.toString.call(val) == "[object String]";
	}
	//简单判断数字
	isNumber (val) {
		if (val === "" || val == null || val == undefined) {
			return false;
		}
		if (!isNaN(val)) {
			//对于空数组和只有一个数值成员的数组或全是数字组成的字符串，isNaN返回false，例如：'123'、[]、[2]、['123'],isNaN返回false,
			//所以如果不需要val包含这些特殊情况，则这个判断改写为if(!isNaN(val) && typeof val === 'number' )
			return true;
		}
		return false;
	}
	//判断有效的数字
	isNumberComplex (val) {
		var reg = /^[+-]?(\d|[1-9]\d+)(\.\d+)?$/;
		return reg.test(val);
	}
	//时间有效的数字 0可以在前面
	isNumberTime (val) {
		var reg = /^[+-]?(\d|[0-9]\d+)(\.\d+)?$/;
		return reg.test(val);
	}
	deepCompare (variableX, variableY) {
		var leftChain, rightChain;

		function compare2Objects (variableX, variableY) {
			var p;
			if (isNaN(variableX) && isNaN(variableY) && typeof variableX === 'number' && typeof variableY === 'number') {
				return true;
			}
			if (variableX === variableY) {
				return true;
			}
			if ((typeof variableX === 'function' && typeof variableY === 'function') ||
				(variableX instanceof Date && variableY instanceof Date) ||
				(variableX instanceof RegExp && variableY instanceof RegExp) ||
				(variableX instanceof String && variableY instanceof String) ||
				(variableX instanceof Number && variableY instanceof Number)) {
				return variableX.toString() === variableY.toString();
			}
			if (!(variableX instanceof Object && variableY instanceof Object)) {
				return false;
			}
			if (variableX.isPrototypeOf(variableY) || variableY.isPrototypeOf(variableX)) {
				return false;
			}
			if (variableX.constructor !== variableY.constructor) {
				return false;
			}
			if (variableX.prototype !== variableY.prototype) {
				return false;
			}
			if (leftChain.indexOf(variableX) > -1 || rightChain.indexOf(variableX) > -1) {
				return false;
			}
			for (p in variableY) {
				if (variableY.hasOwnProperty(p) !== variableX.hasOwnProperty(p)) {
					return false;
				} else if (typeof variableY[p] !== typeof variableX[p]) {
					return false;
				}
			}
			for (p in variableX) {
				if (variableY.hasOwnProperty(p) !== variableX.hasOwnProperty(p)) {
					return false;
				} else if (typeof variableY[p] !== typeof variableX[p]) {
					return false;
				}

				switch (typeof (variableX[p])) {
					case 'object':
					case 'function':

						leftChain.push(variableX);
						rightChain.push(variableY);

						if (!compare2Objects(variableX[p], variableY[p])) {
							return false;
						}

						leftChain.pop();
						rightChain.pop();
						break;

					default:
						if (variableX[p] !== variableY[p]) {
							return false;
						}
						break;
				}
			}

			return true;
		}

		if (arguments.length < 1) {
			return true;
		}

		for (let i = 1, l = arguments.length; i < l; i++) {

			leftChain = [];
			rightChain = [];

			if (!compare2Objects(arguments[0], arguments[i])) {
				return false;
			}
		}

		return true;
	}
}

module.exports = new Utils();